//写cookies
var setCookie = function(name, value, hours) {
	var exp = new Date();
	if(hours) {
		exp.setTime(exp.getTime() + hours * 60 * 60 * 1000);
	} else {
		exp.setTime(exp.getTime() + 30 * 24 * 60 * 60 * 1000); //默认30天
	}
	document.cookie = name + "=" + escape(value) + ";path=/;expires=" + exp.toGMTString();
}
//读取cookies
var getCookie = function(name) {
	var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
	if(arr = document.cookie.match(reg))
		return unescape(arr[2]);
	else
		return null;
}
//清除cookie
var clearCookie = function(name) {
	setCookie(name, "", -1);
}

var getToken = function() {
	var token = getCookie("token");
	return token;
}
Date.prototype.format = function(format) {
	var date = {
		"M+": this.getMonth() + 1,
		"d+": this.getDate(),
		"h+": this.getHours(),
		"m+": this.getMinutes(),
		"s+": this.getSeconds(),
		"q+": Math.floor((this.getMonth() + 3) / 3),
		"S+": this.getMilliseconds()
	};
	if(/(y+)/i.test(format)) {
		format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
	}
	for(var k in date) {
		if(new RegExp("(" + k + ")").test(format)) {
			format = format.replace(RegExp.$1, RegExp.$1.length == 1 ?
				date[k] : ("00" + date[k]).substr(("" + date[k]).length));
		}
	}
	return format;
}

// 去除首位空格的函数
function trim_begin_end(s) {
	s = s + "";
	if(!s) {
		return s;
	}
	return s.replace(/(^\s*)|(\s*$)/g, "");
}